import subprocess

def generate_requirements():
    try:
        result = subprocess.run(['pip', 'freeze'], capture_output=True, text=True, check=True)
        filtered_packages = []
        for line in result.stdout.splitlines():
            if not any(pkg in line for pkg in ['setuptools', 'pip', 'wheel', 'build_artifacts', 'feedstock']):
                if "@ file://" not in line:
                    filtered_packages.append(line)
        
        with open('requirements.txt', 'w') as f:
            f.write('\n'.join(filtered_packages))
        
        print("requirements.txt has been generated successfully.")
    except subprocess.CalledProcessError as e:
        print(f"An error occurred while generating requirements.txt: {e}")

if __name__ == "__main__":
    generate_requirements()
